/*
 * Copyright 2018-present KunMinX
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.henghai.zhenxuan.ui.page.adapter;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DiffUtil;

import com.henghai.zhenxuan.data.bean.AddressBean;
import com.henghai.zhenxuan.data.bean.AdoptListBean;
import com.henghai.zhenxuan.data.bean.IssueTaskBean;
import com.henghai.zhenxuan.data.bean.MyFastMailBean;
import com.henghai.zhenxuan.data.bean.MyHarvestBean;
import com.henghai.zhenxuan.data.bean.MyTeamBean;
import com.henghai.zhenxuan.data.bean.ProductBean;
import com.henghai.zhenxuan.data.bean.ProductInfoBean;
import com.henghai.zhenxuan.data.bean.ProductOrderListBean;
import com.henghai.zhenxuan.data.bean.RaiseBean;
import com.henghai.zhenxuan.data.bean.RankingListBean;
import com.henghai.zhenxuan.data.bean.SysUserPrizesBean;
import com.henghai.zhenxuan.data.bean.UserPointsLogBean;
import com.henghai.zhenxuan.data.bean.WinnerBean;


public class DiffUtils {

    private DiffUtil.ItemCallback<UserPointsLogBean.RowsBean> mIntegralItemCallback;
    private DiffUtil.ItemCallback<ProductOrderListBean.RowsBean> mIntegralOrderCallback;
    private DiffUtil.ItemCallback<IssueTaskBean.RowsBean> mTaskItemCallback;
    private DiffUtil.ItemCallback<RankingListBean.RowsBean> mRankingItemCallback;
    private DiffUtil.ItemCallback<ProductBean.RowsBean> mProductItemCallback;
    private DiffUtil.ItemCallback<ProductInfoBean.ProductFileListBean> mProductImageItemCallback;
    private DiffUtil.ItemCallback<AddressBean> mAdressItemCallback;
    private DiffUtil.ItemCallback<MyFastMailBean> mMyFastMailItemCallback;

    private DiffUtil.ItemCallback<WinnerBean.RowsBean> mWinnerItemCallback;

    private DiffUtil.ItemCallback<SysUserPrizesBean.RowsBean> mPrizeItemCallback;
    private DiffUtil.ItemCallback<MyTeamBean> mMyteamCallback;
    private DiffUtil.ItemCallback<MyHarvestBean> mMyHarvestItemCallback;
    private DiffUtil.ItemCallback<AdoptListBean.RowsDTO> mAdoptBeanItemCallback;
    private DiffUtil.ItemCallback<RaiseBean.RowsDTO> mRaiseItemCallback;

    private DiffUtils() {
    }

    private static final DiffUtils S_DIFF_UTILS = new DiffUtils();

    public static DiffUtils getInstance() {
        return S_DIFF_UTILS;
    }


    public DiffUtil.ItemCallback<WinnerBean.RowsBean> getWinnerItemCallback() {
        if (mWinnerItemCallback == null) {
            mWinnerItemCallback = new DiffUtil.ItemCallback<WinnerBean.RowsBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull WinnerBean.RowsBean oldItem, @NonNull WinnerBean.RowsBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull WinnerBean.RowsBean oldItem, @NonNull WinnerBean.RowsBean newItem) {
                    return oldItem.getId() == newItem.getId();
                }
            };
        }
        return mWinnerItemCallback;
    }
    public DiffUtil.ItemCallback<MyHarvestBean> getMyHarvestItemCallback() {
        if (mMyHarvestItemCallback == null) {
            mMyHarvestItemCallback = new DiffUtil.ItemCallback<MyHarvestBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull MyHarvestBean oldItem, @NonNull MyHarvestBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull MyHarvestBean oldItem, @NonNull MyHarvestBean newItem) {
                    return (oldItem.getHarversId() + "").equals(newItem.getHarversId() + "");
                }
            };
        }
        return mMyHarvestItemCallback;
    }
    public DiffUtil.ItemCallback<RaiseBean.RowsDTO> getRaiseItemCallback() {
        if (mRaiseItemCallback == null) {
            mRaiseItemCallback = new DiffUtil.ItemCallback<RaiseBean.RowsDTO>() {
                @Override
                public boolean areItemsTheSame(@NonNull RaiseBean.RowsDTO oldItem, @NonNull RaiseBean.RowsDTO newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull RaiseBean.RowsDTO oldItem, @NonNull RaiseBean.RowsDTO newItem) {
                    return (oldItem.getPetId()+ "").equals(newItem.getPetId() + "");
                }
            };
        }
        return mRaiseItemCallback;
    }



    public DiffUtil.ItemCallback<AddressBean> getAddressItemCallback() {
        if (mAdressItemCallback == null) {
            mAdressItemCallback = new DiffUtil.ItemCallback<AddressBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull AddressBean oldItem, @NonNull AddressBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull AddressBean oldItem, @NonNull AddressBean newItem) {
                    return (oldItem.getId() + "").equals(newItem.getId() + "");
                }
            };
        }
        return mAdressItemCallback;
    }
    public DiffUtil.ItemCallback<AdoptListBean.RowsDTO> getAdoptItemCallback() {
        if (mAdoptBeanItemCallback == null) {
            mAdoptBeanItemCallback = new DiffUtil.ItemCallback<AdoptListBean.RowsDTO>() {
                @Override
                public boolean areItemsTheSame(@NonNull AdoptListBean.RowsDTO oldItem, @NonNull AdoptListBean.RowsDTO newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull AdoptListBean.RowsDTO oldItem, @NonNull AdoptListBean.RowsDTO newItem) {
                    return (oldItem.getPetId() + "").equals(newItem.getPetId() + "");
                }
            };
        }
        return mAdoptBeanItemCallback;
    }
    public DiffUtil.ItemCallback<MyFastMailBean> getMyFastMailItemCallback() {
        if (mMyFastMailItemCallback == null) {
            mMyFastMailItemCallback = new DiffUtil.ItemCallback<MyFastMailBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull MyFastMailBean oldItem, @NonNull MyFastMailBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull MyFastMailBean oldItem, @NonNull MyFastMailBean newItem) {
                    return (oldItem.getId() + "").equals(newItem.getId() + "");
                }
            };
        }
        return mMyFastMailItemCallback;
    }

    public DiffUtil.ItemCallback<UserPointsLogBean.RowsBean> getIntegralItemCallback() {
        if (mIntegralItemCallback == null) {
            mIntegralItemCallback = new DiffUtil.ItemCallback<UserPointsLogBean.RowsBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull UserPointsLogBean.RowsBean oldItem, @NonNull UserPointsLogBean.RowsBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull UserPointsLogBean.RowsBean oldItem, @NonNull UserPointsLogBean.RowsBean newItem) {
                    return (oldItem.getId() + "").equals(newItem.getId() + "");
                }
            };
        }
        return mIntegralItemCallback;
    }

    public DiffUtil.ItemCallback<MyTeamBean> getMyTeamCallback() {
        if (mMyteamCallback == null) {
            mMyteamCallback = new DiffUtil.ItemCallback<MyTeamBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull MyTeamBean oldItem, @NonNull MyTeamBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull MyTeamBean oldItem, @NonNull MyTeamBean newItem) {
                    return (oldItem.getUserId()).equals(newItem.getUserId());
                }
            };
        }
        return mMyteamCallback;
    }

    public DiffUtil.ItemCallback<ProductOrderListBean.RowsBean> getIntegralOrderCallback() {
        if (mIntegralOrderCallback == null) {
            mIntegralOrderCallback = new DiffUtil.ItemCallback<ProductOrderListBean.RowsBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull ProductOrderListBean.RowsBean oldItem, @NonNull ProductOrderListBean.RowsBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull ProductOrderListBean.RowsBean oldItem, @NonNull ProductOrderListBean.RowsBean newItem) {
                    return (oldItem.getOrderId() + "").equals(newItem.getOrderId() + "");
                }
            };
        }
        return mIntegralOrderCallback;
    }

    public DiffUtil.ItemCallback<RankingListBean.RowsBean> getRankingItemCallback() {
        if (mRankingItemCallback == null) {
            mRankingItemCallback = new DiffUtil.ItemCallback<RankingListBean.RowsBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull RankingListBean.RowsBean oldItem, @NonNull RankingListBean.RowsBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull RankingListBean.RowsBean oldItem, @NonNull RankingListBean.RowsBean newItem) {
                    return oldItem.getUserId().equals(newItem.getUserId());
                }
            };
        }
        return mRankingItemCallback;
    }


    public DiffUtil.ItemCallback<IssueTaskBean.RowsBean> getTaskItemCallback() {
        if (mTaskItemCallback == null) {
            mTaskItemCallback = new DiffUtil.ItemCallback<IssueTaskBean.RowsBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull IssueTaskBean.RowsBean oldItem, @NonNull IssueTaskBean.RowsBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull IssueTaskBean.RowsBean oldItem, @NonNull IssueTaskBean.RowsBean newItem) {
                    return oldItem.getTaskTitle().equals(newItem.getTaskTitle());
                }
            };
        }
        return mTaskItemCallback;
    }

    public DiffUtil.ItemCallback<ProductBean.RowsBean> getProductItemCallback() {
        if (mProductItemCallback == null) {
            mProductItemCallback = new DiffUtil.ItemCallback<ProductBean.RowsBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull ProductBean.RowsBean oldItem, @NonNull ProductBean.RowsBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull ProductBean.RowsBean oldItem, @NonNull ProductBean.RowsBean newItem) {
                    return oldItem.getProductName().equals(newItem.getProductName());
                }
            };
        }
        return mProductItemCallback;
    }

    public DiffUtil.ItemCallback<ProductInfoBean.ProductFileListBean> getProductImageItemCallback() {
        if (mProductImageItemCallback == null) {
            mProductImageItemCallback = new DiffUtil.ItemCallback<ProductInfoBean.ProductFileListBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull ProductInfoBean.ProductFileListBean oldItem, @NonNull ProductInfoBean.ProductFileListBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull ProductInfoBean.ProductFileListBean oldItem, @NonNull ProductInfoBean.ProductFileListBean newItem) {
                    return oldItem.getProductId().equals(newItem.getProductId());
                }
            };
        }
        return mProductImageItemCallback;
    }

    public DiffUtil.ItemCallback<SysUserPrizesBean.RowsBean> getPrizeItemCallback() {
        if (mPrizeItemCallback == null) {
            mPrizeItemCallback = new DiffUtil.ItemCallback<SysUserPrizesBean.RowsBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull SysUserPrizesBean.RowsBean oldItem, @NonNull SysUserPrizesBean.RowsBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull SysUserPrizesBean.RowsBean oldItem, @NonNull SysUserPrizesBean.RowsBean newItem) {
                    return (oldItem.getId() + "").equals(newItem.getId() + "");
                }
            };
        }
        return mPrizeItemCallback;
    }
}
